<template>
  <div class="channel-jurisdiction">
    <el-container class="container-box">
      <el-header>
        <el-form inline :model="searchForm" ref="searchForm">
          <el-form-item label="企业名称" prop="companyName">
            <el-input
              v-model="searchForm.companyName"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item label="公司类型" prop="companyType">
            <el-select v-model="searchForm.companyType" placeholder="请选择">
              <el-option
                v-for="item in companyTypeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="自定义编码" prop="companyCode">
            <el-input
              v-model="searchForm.companyCode"
              placeholder="请输入"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <buttonLoading
              :loading="submitLoading"
              @searchForm="searchCompany"
            />
            <el-button @click="reset">
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </el-header>
      <el-editable
        :data="tableData"
        :columns="columns"
        v-loading="getListLoading"
        height="200"
      >
        <template slot="default-operation" slot-scope="scope">
          <el-button type="text" @click="toMenuList(scope)">
            菜单配置
          </el-button>
        </template>
      </el-editable>
      <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="PAGE_NUMBER"
        :page-size="pageSize"
        :layout="PAGINATION_LAYOUT"
        :total="totalElements"
      />
    </el-container>
  </div>
</template>
<script>
import buttonLoading from '@components/el-button-loading'
import ElEditable from '@components/el-editable'
import {columns, companyTypeOptions} from './const'
import {staffUcOrganPage} from '@const/api_staffCenter'
import {PAGE_NUMBER, PAGINATION_LAYOUT} from '@const/common'
import {hasIn} from 'lodash'
export default {
  components: {
    buttonLoading,
    ElEditable
  },
  data() {
    return {
      searchForm: {
        companyName: '',
        companyType: '',
        companyCode: ''
      },
      companyTypeOptions,
      submitLoading: false,
      tableData: [],
      getListLoading: false,
      columns,
      curPage: 1, // 当前页
      PAGE_NUMBER, // 页码数组
      PAGINATION_LAYOUT, // 页码功能布局
      pageSize: PAGE_NUMBER[0], // 一页的数量
      totalElements: 0
    }
  },
  mounted() {
    this.searchCompany()
  },
  methods: {
    // 查询
    searchCompany() {
      this.submitLoading = true
      this.getListLoading = true
      this.$axios({
        method: 'post',
        url: staffUcOrganPage,
        data: {
          ...this.searchForm,
          page: this.curPage,
          pageSize: this.pageSize
        }
      })
        .then(res => {
          let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
          this.tableData = obj.content
          this.totalElements = obj.totalElements
        })
        .finally(res => {
          this.submitLoading = false
          this.getListLoading = false
        })
    },
    // 重置
    reset() {
      this.$refs.searchForm.resetFields()
    },
    // 页码更改
    handleSizeChange(size) {
      this.pageSize = size
      this.searchCompany()
    },
    // 切换不一样的页面,重置一切数据
    handleCurrentChange(curPage) {
      this.curPage = curPage
      this.searchCompany()
    },
    toMenuList(data) {
      this.$router.push({
        path: `/systemSetup/enterprise/newmenuList`,
        query: {
          id: data.row.companyId
        }
      })
    }
  }
}
</script>
<style lang="less">
.channel-jurisdiction {
  .container-box {
    height: 100%;
    overflow: auto;
    display: flex;
  }

  .pagination {
    padding-top: 10px;
    display: flex;
    justify-content: flex-end;
    padding-right: 0;
  }
}
</style>
